﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Skynet.ServiceContracts;
using System.ServiceModel.Activation;
using Skynet.BusinessEntities;
using Microsoft.Practices.Unity;
namespace Skynet.ServiceImplementation
{    
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class SkynetLibraryWeb : ISkynetLibraryWeb
    {
        [Dependency]
        public BusinessLogic.BusinessComponents.IBCExams BCExams { get; set; }
        [Dependency]
        public Infrastructure.Aspect.Services.Traslator.IEntityTranslatorService EntityTranslatorService { get; set; }

        [Dependency]
        public Infrastructure.Aspect.Inspectors.IMethodAuditService MethodAuditService { get; set; }
        


        public DateTime GetSystemDate()
        {
            return DateTime.Now;         
        }

        public List<ExamCategory> FindExamCategories(ServiceContracts.DataContracts.DCExamFindCategoryOperation operation)
        {
            return null;
        }
        public void RegisterMethodInterceptor(Guid Id, string Solution, Guid Application, Guid Operation, string Module, string ClassName, string MethodName, string Created)
        {
            if (Created.ToLower().Contains("utc"))
            {
                Created = Created.Replace("UTC", "");
            }
            var method = new Infrastructure.Aspect.Inspectors.MethodAudit();
            method.Id = Id;
            method.Solution = Solution;
            method.Application = Application;
            method.Module = Module;
            method.Created = DateTime.Parse(Created).ToLocalTime();
            method.ClassName = ClassName;
            method.Method = MethodName;
            method.Operation = Operation;
            this.MethodAuditService.AddMethodAudit(method);
        }

        #region ISkynetLibraryWeb Members


        public double GetOperationAverage(string solution, string module, string classname, string method)
        {
            return this.MethodAuditService.GetTimeAverage(solution, module, classname, method);
        }

        #endregion
    }
}
